from flask import Blueprint, request
from flask_cors import CORS

from services.dongchedi import get_dongchedi_hotspot_from_db
from blueprints.utils import response_error, response_success, is_page_out_of_bounds

dongchedi_bp = Blueprint("dongchedi", __name__, url_prefix="/dongchedi")

CORS(
    dongchedi_bp, resources={r"/*": {"origins": "http://localhost:5173", "methods": ["GET"], "supports_credentials": True}}
)

@dongchedi_bp.route("/hot", methods=["GET"])
def get_dongchedi_hotspot():
    """
    获取懂车帝热搜数据

    测试地址：http://127.0.0.1:5000/dongchedi/hot
    """
    # 调用服务层函数获取数据
    result = get_dongchedi_hotspot_from_db()
    result = [hotspot.to_dict() for hotspot in result]
    return response_success(result)
